{% extends "admin/layout.html" %}

{% block title %}审批流程管理 - {{ super() }}{% endblock %}

{% block content %}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2">审批流程管理</h1>
    <div class="btn-toolbar mb-2 mb-md-0">
        <a href="{{ url_for('approval.create_flow') }}" class="btn btn-sm btn-outline-primary">
            <i class="fas fa-plus"></i> 新建审批流程
        </a>
    </div>
</div>

<div class="card shadow-sm">
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>流程名称</th>
                        <th>关联部门</th>
                        <th>步骤数量</th>
                        <th>是否默认</th>
                        <th>创建时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for flow in flows %}
                    <tr>
                        <td>{{ flow.name }}</td>
                        <td>{{ flow.department.name if flow.department else '通用' }}</td>
                        <td>{{ flow.steps|length }}</td>
                        <td>
                            {% if flow.is_default %}
                            <span class="badge bg-success">是</span>
                            {% else %}
                            <span class="badge bg-secondary">否</span>
                            {% endif %}
                        </td>
                        <td>{{ flow.created_at.strftime('%Y-%m-%d') }}</td>
                        <td>
                            <div class="btn-group btn-group-sm">
                                <a href="{{ url_for('approval.flow_detail', flow_id=flow.id) }}" class="btn btn-outline-info">详情</a>
                                <a href="{{ url_for('approval.edit_flow', flow_id=flow.id) }}" class="btn btn-outline-primary">编辑</a>
                                <form method="post" action="{{ url_for('approval.delete_flow', flow_id=flow.id) }}" class="d-inline">
                                    <button type="submit" class="btn btn-outline-danger" onclick="return confirm('确定删除此审批流程吗？')">删除</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="6" class="text-center text-muted">暂无审批流程</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}